package sonic.game.character;

import java.awt.Graphics;
import java.util.ArrayList;

import sonic.game.Game;
import sonic.game.animation.Animation;
import sonic.game.animation.AnimationSet;
import sonic.game.tile.DynamicTile;
import sonic.game.tile.Tile;
import sonic.game.util.Vector2D;

/**
 * Game Character
 * 
 * Base class for all characters in the game, including Player and AI
 * 
 * @author RGreenlees
 *
 */

public class GameCharacter extends DynamicTile
{
	// How fast the character accelerates to max speed
	public float accelRate = 2.0f;
	public float maxGroundSpeed = 0.0f;
	public float maxFlyingSpeed = 0.0f;
	
	/* Characters use animation sets rather than single animations. Useful if you want to have different animations
	   with the same name for different circumstances, e.g. Regular Sonic / Super Sonic animations */
	protected ArrayList<String> animSetID = new ArrayList<String>();
	protected ArrayList<AnimationSet> animSets = new ArrayList<AnimationSet>();
	
	// Current active animation set
	public AnimationSet currentAnimationSet;
	
	public int health = 1;
	
	// Will flip the character's animation if they're looking left
	protected boolean bFaceLeft = false;
	
	public GameCharacter(Vector2D startLoc)
	{
		super(startLoc);
		physicsType = ePhysicsType.PHYS_FALLING;
	}
	
	public GameCharacter()
	{
		
	}
	
	public void takeDamage(Tile damager, int dmg)
	{
		super.takeDamage(damager, dmg);
		health -= dmg;
	}
	
	/** Switch out animation sets */
	public void setCurrentAnimSet(String animSetID)
	{
		currentAnimationSet = animSets.get(animSetID.indexOf(animSetID));
	}
	
	
	public Animation getCurrentAnim()
	{
		return currentAnimationSet.getCurrentAnimation();
	}
	
	public void addAnimationSet(String id, AnimationSet newAnimSet)
	{
		animSetID.add(id);
		animSets.add(animSetID.indexOf(id), newAnimSet);
	}
	
	public void paint(Graphics g)
	{
		g.drawImage(currentAnimationSet.getCurrentFrame(bFaceLeft), (int) location.x + (320-(int) Game.camera.location.x), (int) location.y + (240-(int) Game.camera.location.y), null);
	}
	
	public void die()
	{
		destroy();
	}

	
}
